/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				OilCondition
 
Function						: 				Provides a class for holding 
												the oil condition
****************************************************************************/
package planninglanguage.conditions;

import mre.MRE;

import org.jdom.Element;

import util.XMLWriter;
import base.WargusGameState;


public class OilCondition extends Condition {

	int m_minOil;
	
	public OilCondition(int a_minOil)
	{
		m_minOil = a_minOil;
	}
	public String toString(int tabs)
	{
		String n = super.toString(tabs);
		n = n + "Min Oil needed is:" + m_minOil;
		return n;
	}
	public boolean compare(BuildingCompleteCondition c)
	{
		return true;
	}
	
	public boolean test(WargusGameState a_gameState)
	{
//		System.out.println("OilCondition: test( oil = " + m_minOil + ")");	
		
		if (a_gameState.getPlayer().getOil()-MRE.allocated_oil >= m_minOil) return true;
		  																  else return false;			
	}
	
	public void writeXML(XMLWriter w) {
		w.tag("condition type=\""+this.getClass().getSimpleName()+"\"");
		{
			w.tag("min-oil", m_minOil);
		}
		w.tag("/condition");
	}
	
	protected static Condition loadConditionFromXML(Element e) {
		return new OilCondition(Integer.parseInt(e.getChildText("min-oil")));
	}
}
